package com.beyondsoft.sabg.edu.model.db;

import cn.hutool.core.util.StrUtil;
import com.beyondsoft.sabg.edu.model.db.core.BasicEntity;
import com.beyondsoft.sabg.edu.model.enums.FormSettingEnum;
import com.beyondsoft.sabg.edu.model.exception.InvalidParamException;
import lombok.*;
import lombok.extern.slf4j.Slf4j;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import java.util.List;

@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Slf4j
@Table(name = "nothing-formSetting")
public class FormSetting extends BasicEntity {



    private String settingKey;
    @Size(max = 5000)
    private String settingValue;

    public void setSettingKey(String settingKey) {
        checkKeyType(settingKey);
        this.settingKey = settingKey;
    }

    private void checkKeyType(String key) {
        List<String> keyNameList = FormSettingEnum.getENames();
        if (!keyNameList.contains(key)) {
            log.error("the {} is not expect,key must in {}", key, keyNameList);
            throw new InvalidParamException(StrUtil.format("the {} is not expect,key must in {}", key, keyNameList));
        }
    }
}
